/**
 *
 * $Id: IOServer.i,v 1.1 2009-09-29 10:07:16 ttaipalu Exp $
 *
 * \file
 * \brief Python wrap for MaCI - IO Server interface
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 * \author Tapio Taipalus <tapio.taipalus@tkk.fi>
 */
%module IOServer

%include std_string.i
%include std_list.i
//%include std_map.i
%include "typemaps.i"
//%include std_vector.i

%{
	#include "MaCI.hpp"
	#include "IOData.hpp"
	#include "IOServer.hpp"
	#include "thread.hpp"
	#include "sync.hpp"
	#include <list>
%}
	
	%include "IOTypes.i"
	%include "IOData.i"
	%include "../MaCIError.i"
	%include "../MaCI.i"
	%include "../MaCICtrl/MaCICtrlServer.i"
	

// Forward declare gimi::GIMI
namespace gimi {
  class GIMI;
  class GIMIMessage;
}


namespace MaCI{
  namespace IO{

    /** MaCI - IO Server interface
     * 
     * This class contains the methods and types for providing
     * the IO service in the GIMnet.
     */
    class CIOServer : public MaCI::CMaCI
    {
    public:

      /** Constructor.
       * 
       * Constructor of the IOServer. This requires;
       * a pointer to Initialized and connected GIMI, minor
       * number of this interface (Used as GIMI minor number)
       *
       * @param[in] aMaCICtrlServerPtr Pointer to GIMI used for communication
       * @param[in] aInterfaceMinor Interface minor number. Usually
       * used to indicate the instance of devices of same
       * type.
       */
      CIOServer(MaCI::MaCICtrl::CMaCICtrlServer *aMaCICtrlServerPtr, const int aInterfaceMinor);

      /** Destructor.
       */
      ~CIOServer();

      /** Opens IO Server
       *
       * Opens the IO Server,  basicly registers device to GIMI.
       *  
       * @return                Returns a value of type EMaCIError. 
       *                        
       * \see EMaCIError
       */
      MaCI::EMaCIError DoOpen(void);

      /** Close device.
       *
       * Closes the device. Closes all GIMI registrations and queues.
       *
       * @return                Returns a value of type EMaCIError.
       *
       * \see EMaCIError
       */
      MaCI::EMaCIError DoClose(void);

      /** Wait for a Command.
       *
       * This function waits until new command arrives or timeout occurs.
       * If there is unhandled commands since last read, the next
       * in queue is returned. If you want to clear the queue between calls,
       * use ClearCommandBuffer() function.
       *
       * When a command is succesfully returned, the user can inspect
       * the current command through the GetCommand() call of
       * class CIOData. Then, according to command and its
       * specification, additional datafields may be present, they
       * can be queried by similar Get... functions. See the 
       * description of the data encoder/decoder module CIOData.
       *
       * 
       * \see ClearCommandBuffer()
       * \see CIOData
       * \see MaCI::EMaCIError
       * 
       * @param[out] aData      Reference to IOData. This will
       *                        be filled with incoming command when
       *                        this call is completed succesfully.
       * @param[out] aInfo      Reference to replyInfo. Use this replyInfo 
       *                        to SendReply-function when you have to send 
       *                        a Reply.
       * @param[in] aTimeout_ms Timeout to wait until operation fails
       *                        for timeout.
       * @return                'KMaCIOK'  when succesfully received
       *                        a new command. KMaCITimeout when operation
       *                        timed out before a command was received.
       *                        Other errors returned when appropriate.
       *                        (See the MaCI::EMaCIError for description)
       * \see EMaCIError
       */
      MaCI::EMaCIError WaitCommand(MaCI::IO::CIOData &aData, 
	  MaCI::IO::TReplyInfo &aInfo,
                                   const unsigned int aTimeout_ms);

      /** Sends reply message to client
       *
       * @param[in] aData       Reference to IOData. This data will be sent to
       *                        client for reply
       * @param[in] aInfo       Reference to replyInfo. Get this replyinfo from
       *                        WaitCommand.
       * @return                'KMaCIOK' when reply message succesfully sent.
       *                        Other errors returned when appropriate.
       *                        (See the MaCI::EMaCIError for description)
       * \see EMaCIError
       */
      MaCI::EMaCIError SendReply(MaCI::IO::CIOData &aData,
	  MaCI::IO::TReplyInfo &aInfo);

    };

  }

}
